package com.example.applicationcontextaware.event;

import com.example.applicationcontextaware.bean.TestEntity;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;


/**
 * 异步监听事件
 */
@Slf4j
@AllArgsConstructor
public class TestListener {

    @Async
    @Order
    @EventListener(TestEvent.class)
    public void saveSysLog(TestEvent event) throws InterruptedException {
        TestEntity sysLog = (TestEntity) event.getSource();
        Thread.sleep(1000);
        System.err.println(sysLog);
    }
}
